import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login.vue'
import article from '../views/article.vue'

import index from "../components/hyzx/index.vue"

import userInformation from "../components/hyzx/userInformation.vue"

import storeInformation from "../components/dpgl/storeInformation.vue"
import userManagement from "../components/dpgl/userManagement.vue"
import userManagement_edit from "../components/dpgl/edit.vue"
import productUpload from "../components/dpgl/productUpload.vue"
import ProductList from "../components/dpgl/ProductList.vue"
import orderList from "../components/dpgl/orderList.vue"
import prizeUpload from "../components/dpgl/prizeUpload.vue"
import prizeList from "../components/dpgl/prizeList.vue"
import shopDetails from "../components/dpgl/shopDetails.vue"

Vue.use(VueRouter)

// 重复点击路由防止报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
 
const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/article',
    name: 'article',
    component: article,
    redirect:'/userInformation/',
    children: [
      {
        path: "/storeInformation",
        name: "storeInformation",
        component: storeInformation,
      },

      {
        path: "/userManagement",
        name: "userManagement",
        component: userManagement,
      },

      {
        path: "/userManagement_edit",
        name: "userManagement_edit",
        component: userManagement_edit,
      },
      {
        path: '/userInformation',
        name: 'userInformation',
        component: userInformation,
      },
      {
        path: '/productUpload',
        name: 'productUpload',
        component: productUpload,
      },
      {
        path: '/ProductList',
        name: 'ProductList',
        component: ProductList,
      },
      {
        path: '/orderList',
        name: 'orderList',
        component: orderList,
      },
      {
        path: '/shopDetails',
        name: 'shopDetails',
        component: shopDetails,
      },
      {
        path: '/prizeUpload',
        name: 'prizeUpload',
        component: prizeUpload,
      },
      {
        path: '/prizeList',
        name: 'prizeList',
        component: prizeList,
      }
    ]
  }

]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const user = window.sessionStorage.getItem('user')
  if (!user) return next('/login')
  next()
})
export default router